package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizOftenBuy;
import com.member.shop.domain.SysBizOperationLog;
import com.member.shop.service.ISysBizOperationLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【操作日志】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-01-15
 **/
@RestController
@RequestMapping("/shop/operationLog")
public class SysBizOperationLogController extends BaseController {
    @Resource
    private ISysBizOperationLogService sysBizOperationLogService;

    /**
     * 查询操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('shop:operationLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizOperationLog sysBizOperationLog) {
        startPage();
        setTenantId(sysBizOperationLog);
        List<SysBizOperationLog> list = sysBizOperationLogService.selectSysBizOperationLogList(sysBizOperationLog);
        return getDataTable(list);
    }

    private void setTenantId(SysBizOperationLog sysBizOperationLog) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizOperationLog.setTenantId(tenantId);
        }
    }

    /**
     * 导出操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('shop:operationLog:export')")
    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizOperationLog sysBizOperationLog) {
        LambdaQueryWrapper<SysBizOperationLog> queryWrapper = new LambdaQueryWrapper<SysBizOperationLog>();
        setTenantId(sysBizOperationLog);
        List<SysBizOperationLog> list = sysBizOperationLogService.selectSysBizOperationLogList(queryWrapper);
        ExcelUtil<SysBizOperationLog> util = new ExcelUtil<SysBizOperationLog>(SysBizOperationLog.class);
        util.exportExcel(response, list, "操作日志数据");
    }

    /**
     * 获取操作日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:operationLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizOperationLogService.selectSysBizOperationLogById(id));
    }

    /**
     * 新增操作日志
     */
    @PreAuthorize("@ss.hasPermi('shop:operationLog:add')")
    @Log(title = "操作日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizOperationLog sysBizOperationLog) {
        return toAjax(sysBizOperationLogService.insertSysBizOperationLog(sysBizOperationLog));
    }

    /**
     * 修改操作日志
     */
    @PreAuthorize("@ss.hasPermi('shop:operationLog:edit')")
    @Log(title = "操作日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizOperationLog sysBizOperationLog) {
        return toAjax(sysBizOperationLogService.updateSysBizOperationLog(sysBizOperationLog));
    }

    /**
     * 删除操作日志
     */
    @PreAuthorize("@ss.hasPermi('shop:operationLog:remove')")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizOperationLogService.deleteSysBizOperationLogByIds(ids));
    }
}
